package com.tul.exercise.base.thread.base;

/**
 * 使用线程创建可响应的界面
 */
public class ResponsiveUI extends Thread{
    private static volatile double d = 1;
    public ResponsiveUI() {
        // 设置为后台线程
        setDaemon(true);
        start();
    }
    public void run() {
        while(true) {
            d = d + (Math.PI + Math.E)/d;
        }
    }

    public static void main(String[] args) throws Exception{
        // new UnresponsiveUI();

        // 后台的计算程序
        new ResponsiveUI();

        // 响应main线程的输入操作，并输出结果
        System.in.read();
        System.out.println(d);
    }
}

/**
 *
 */
class UnresponsiveUI {
    private volatile  double d = 1;

    public UnresponsiveUI() throws Exception{
        while (d >0) {
            d = d + (Math.PI + Math.E)/d;

            // 永远读不到数据
            System.in.read();
        }
    }
}
